import {ModalForm, ProFormText} from "@ant-design/pro-components";
import {CustomerChannelVO} from "@/services/CustomerChannelService";
import {useRef, useState} from "react";
import {ProFormColorPicker, ProFormInstance} from "@ant-design/pro-form/lib";

export interface CustomerChannelUpdateModalProps {
  onFinish: (formData: any) => Promise<boolean | void>;
  customerChannel?: CustomerChannelVO;
  open: boolean;
  onOpenChange: (state: boolean) => void;
}

const CustomerChannelUpdateModal = (props: CustomerChannelUpdateModalProps) => {
  const formRef = useRef<ProFormInstance>()
  return <>
    <ModalForm
      key={props.customerChannel?.id || -1}
      formRef={formRef}
      title={props.customerChannel ? "修改客资渠道" : "添加客资渠道"}
      open={props.open}
      initialValues={props.customerChannel}
      onFinish={props.onFinish}
      onOpenChange={props.onOpenChange}
    >
      <ProFormText
        name="id"
        hidden
      />
      <ProFormText
        label="渠道名"
        name="channelName"
      />
      <ProFormColorPicker
        label="标签颜色"
        name="color"
      />
    </ModalForm>
  </>
}

export default CustomerChannelUpdateModal
